<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>设置网站基本信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="/static/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
    <style type="text/css">
        .uploadImg {
            border: none;
            width: 150px;
            display: block;
            margin-top: 10px;
        }
    </style>
</head>

<body layadmin-themealias="default">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">站点信息设置</div>
                <div class="layui-card-body" pad15>

                    <form class="layui-form" wid100="" lay-filter="">

                        <div class="layui-form-item">
                            <label class="layui-form-label">网站名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="web_name" value="{$webInfo['web_name']}"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="web_status" {if $webInfo['web_status']==1}checked{/if}
                                lay-skin="switch" lay-text="启用|禁用">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">机构默认图</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="upload">上传图片</button>
                                    {if $webInfo['web_institution_default_image']}
                                    <img id="demo1" class="uploadImg" src="{$webInfo['web_institution_default_image']}">
                                    {else/}
                                    <img id="demo1" class="uploadImg">
                                    {/if}
                                    <input type="hidden" name="web_institution_default_image" id="web_insitution_default_image" value="{$webInfo['web_institution_default_image']}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">好课默认图</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="upload2">上传图片</button>
                                    {if $webInfo['web_good_class_default_image']}
                                    <img id="demo2" class="uploadImg" src="{$webInfo['web_good_class_default_image']}">
                                    {else/}
                                    <img id="demo2" class="uploadImg">
                                    {/if}
                                    <input type="hidden" name="web_good_class_default_image" id="web_good_class_default_image" value="{$webInfo['web_good_class_default_image']}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">搜索费用(元)</label>
                            <div class="layui-input-block">
                                <input type="number" name="web_search_fee" value="{$webInfo['web_search_fee']}"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">搜索有效时间(分钟)</label>
                            <div class="layui-input-block">
                                <input type="number" name="web_search_time" value="{$webInfo['web_search_time']}"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">搜索免费次数</label>
                            <div class="layui-input-block">
                                <input type="number" name="web_search_free_num" value="{$webInfo['web_search_free_num']}"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">搜索提示信息</label>
                            <div class="layui-input-block" style="z-index: 1;">
                                    <textarea name="web_search_hint" id="hint" cols="30"
                                              rows="10">{$webInfo['web_search_hint']}</textarea>
                            </div>
                        </div>
                        <input type="hidden" name="id" value="{$webInfo['web_id']}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">版权信息</label>
                            <div class="layui-input-block" style="z-index: 1;">
                                    <textarea name="web_copyright" cols="30"
                                              rows="10" class="layui-textarea">{if $webInfo['web_copyright']!=""}{$webInfo['web_copyright']}{/if}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="setwebsiteinfo">确认修改</button>
                                <button id="reset" class="layui-btn layui-btn-primary">重新填写</button>
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
</div>




<script src="/static/layuiadmin/layui/layui.js"></script>
<script src="/static/layuiadmin/lib/jquery.min.js"></script>
<script>
    var ue = UE.getEditor("hint", {initialFrameHeight: 300}); //富文本编辑器对象
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    });
    layui.use('form', function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;
        //自定义验证规则
        form.verify({
        });

        form.on('submit(setwebsiteinfo)', function (data) {
            var field = data.field;
            $.ajax({
                type: 'POST',
                url: "{:url ('admin/website/show')}",
                dataType: 'json',
                data: field,//往后台发送的是data.field，即一个{name：value}的数据结构
                async: true,
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, { icon: 1, time: 1500 }, function () {
                        });
                    } else {
                        layer.msg(res.msg, { icon: 5, time: 1500 }, function () {
                            window.location.reload();
                        });
                    }
                }

            });
            return false;
        });
        return false;
    });
    $("#reset").click(function () {
        layer.confirm("已编辑的数据将不会被保存！", { icon: 3, title: "重新填写" }, function (index) {
            layer.close(index); //关闭询问框
            //下面写具体的逻辑代码
            window.location.reload();
        })
        return false;
    });
    layui.use("upload",function(){
        var upload=layui.upload;
        var uploadInst = upload.render({
            elem: '#upload'
            , url: "{:url('admin/Website/uploadImg')}"
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var src = res.data.src;
                $("#web_insitution_default_image").val(src);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        var uploadInst2 = upload.render({
            elem: '#upload2'
            , url: "{:url('admin/Website/uploadImg')}"
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var src = res.data.src;
                $("#web_good_class_default_image").val(src);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst2.upload();
                });
            }
        });
    })



</script>
</body>

</html>
